package com.brisk.web.controller.applet;

import com.ruoyi.applet.domain.AppletExam;
import com.ruoyi.applet.service.IAppletExamService;
import com.brisk.common.annotation.Log;
import com.brisk.common.core.controller.BaseController;
import com.brisk.common.core.domain.AjaxResult;
import com.brisk.common.core.page.TableDataInfo;
import com.brisk.common.enums.BusinessType;
import com.brisk.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * examController
 *
 * @author PengFei Deng
 * @date 2022-04-14
 */
@RestController
@RequestMapping("/applet/exam")
public class AppletExamController extends BaseController {
    @Autowired
    private IAppletExamService appletExamService;

    /**
     * 查询exam列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletExam appletExam) {
        startPage();
        List<AppletExam> list = appletExamService.selectAppletExamList(appletExam);
        return getDataTable(list);
    }

    /**
     * 导出exam列表
     */
    @Log(title = "exam", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppletExam appletExam) {
        List<AppletExam> list = appletExamService.selectAppletExamList(appletExam);
        ExcelUtil<AppletExam> util = new ExcelUtil<AppletExam>(AppletExam.class);
        util.exportExcel(response, list, "exam数据");
    }

    /**
     * 获取exam详细信息
     */
    @GetMapping(value = "/{examId}")
    public AjaxResult getInfo(@PathVariable("examId") Integer examId) {
        return AjaxResult.success(appletExamService.selectAppletExamByExamId(examId));
    }

    /**
     * 新增exam
     */
    @Log(title = "exam", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletExam appletExam) {
        appletExam.setCreateBy(getUsername());
        return appletExamService.insertAppletExam(appletExam);
    }

    /**
     * 修改exam
     */
    @Log(title = "exam", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletExam appletExam) {
        return toAjax(appletExamService.updateAppletExam(appletExam));
    }

    /**
     * 删除exam
     */
    @Log(title = "exam", businessType = BusinessType.DELETE)
    @DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable Integer[] examIds) {
        return toAjax(appletExamService.deleteAppletExamByExamIds(examIds));
    }
}
